package com.example.mypro;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import com.example.util.HttpUtil;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SendActivity extends Activity implements OnClickListener{
	private EditText send_nr;
	private String send_zl;
	private Button send;
	private Button cancel;
	private Intent intent;
	private String result1;
	private String time;
	private String xh;
	private String xm;
	private GetData getData;
	private Map<String, String> map = new HashMap<String, String>();
	@SuppressLint("SimpleDateFormat")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_send);
		SimpleDateFormat formatter = new SimpleDateFormat ("MM月dd日");
		send =(Button)findViewById(R.id.send);
		cancel =(Button)findViewById(R.id.cancel);
		send_nr=(EditText)findViewById(R.id.send_tv_nr);
		Date curDate = new Date(System.currentTimeMillis());
		 time = formatter.format(curDate);
		intent=getIntent();
		send_zl=intent.getStringExtra("xyq_zl");
		xh = intent.getStringExtra("xs_xh");
		xm =intent.getStringExtra("xs_xm");
		send.setOnClickListener(this);
		cancel.setOnClickListener(this);
		}
	@SuppressLint("ShowToast")
	class GetData extends AsyncTask<Void, Void, String> {

		@SuppressLint("ShowToast")
		@Override
		protected String doInBackground(Void... params) {
			System.out.println("doInBackground");					
			map.put("xyq_xs_xh",xh);
			map.put("xyq_xs_xm",xm );
			map.put("xyq_sj", time);
			map.put("xyq_nr", send_nr.getText().toString().trim());
			map.put("xyq_zl", send_zl);
		    String servlet= "XiaoYuanQiangServlet";
			String method="save";
		    result1= HttpUtil.sendHttp(servlet,method,map);
			return result1;
		}

		@Override
		protected void onProgressUpdate(Void... values) {
			super.onProgressUpdate(values);

		}

		protected void onPostExecute(String result) {
			super.onPostExecute(result);
	
			
		}

	}
	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.send) {	
			getData = new GetData();
			getData.execute();
			  if(!"false".equals(result1))
			  {
				  Toast.makeText(this, "发送成功",Toast.LENGTH_LONG).show();  
				  this.finish();
			  }
			  else{Toast.makeText(this, "发送失败",Toast.LENGTH_LONG).show();}
	    }
		if (v.getId() == R.id.cancel) {
			this.finish();
		}
}//05-19 18:44:52.185: I/System.out(5813): http://42.51.154.196:8080/MyProgram/XiaoYuanQiangServlet?method=save&xyq_nr=凤飞飞&xyq_xs_xm=尹峰&xyq_sj=05月19日&xyq_zl=失物招领&xyq_xs_xh=2011111178

	}
